﻿$(document).ready(function () {
    $.ajax({
        type: "post",
        data: { action: "GetList" },
        dataType: "json",
        url: "../../Ajax/LotteryPoolAjax.ashx",
        beforeSend: function () {
        },
        success: function (data) {
            var json = data.json;
            var tbody = "";
            $.each(json, function (k, v) {
                tbody += "<tr  id='" + v.ID + "'>"
                tbody += "<td><lable name='lblName' id='lblName'>";
                tbody += v.Name;
                tbody += "</lable></td>";
                tbody += "<td><lable name='lblPoolNum'  id='lblPoolNum'>";
                tbody += v.PoolNum
                tbody += "</lable></td>";
                tbody += "<td><lable name='lblEditTime'  id='lblEditTime'>";
                tbody += v.EditTime;
                tbody += "</lable></td>";
                tbody += "<td><lable name='lblEditNum'  id='lblEditNum'>";
                tbody += v.EditNum;
                tbody += "</lable></td>";
                tbody += "<td><lable name='lblPoolBet'  id='lblPoolBet'>";
                tbody += v.PoolBet;
                tbody += "</lable></td>";
                tbody += "<td><lable name='lblIsOpen'  id='lblIsOpen'>";
                tbody += v.IsOpen;
                tbody += "</lable></td>";
                tbody += "<td><lable name='lblRemark'  id='lblRemark'>";
                tbody += v.Remark;
                tbody += "</lable></td>";
                tbody += "<td>";
                tbody += "<input type='button' id='btnEdit' value='更新'>"
                tbody += "</td>";
                tbody += "</tr>"
            })
            $("#tb1").empty().append(tbody)

            if (eventID != 0) SeltMould(eventID, eventName);
        },
        complete: function () {
        },
        error: function () {
        }
    });

    $("#btnEdit").live("click", function () {
        var content = "";
        content = "<table><tr><td>名称：<input type='text' id='txtName' disabled='disabled' value='" + $("#lblName").text() + "' style='width:200px;float:right' /></td></tr>";
        content += "<tr><td>奖池数量：<input type='text' id='txtPoolNum' value='" + $("#lblPoolNum").text() + "' style='width:200px;float:right' /></td></tr>";
        content += "<tr><td>更新时间（秒）：<input type='text' id='txtEditTime' value='" + $("#lblEditTime").text() + "' style='width:200px;float:right' /></td></tr>";
        content += "<tr><td>更新数量：<input type='text' id='txtEditNum' value='" + $("#lblEditNum").text() + "' style='width:200px;float:right' /></td></tr>";
        content += "<tr><td>奖池倍率：<input type='text' id='txtPoolBet' value='" + $("#lblPoolBet").text() + "' style='width:200px;float:right' /></td></tr>";
        content += $("#lblIsOpen").text() == "True" ? "<tr><td>是否启用：<input type='radio' name='radioIsOpen' id='radioisTure' value='True' checked='checked' /><lable>是</lable><input type='radio' name='radioIsOpen' id='radioisfalse' value='False'/><lable>否</lable></td></tr>"
                : "<tr><td>是否启用：<input type='radio' name='radioIsOpen' id='radioisTure' value='True' /><lable>是</lable><input type='radio' name='radioIsOpen' id='radioisfalse' value='False' checked='checked' /><lable>否</lable></td></tr>"
        content += "<tr><td>备注：<textarea  cols='50' rows='5' id='txtRemark' style='width:197px;float:right'>" + $("#lblRemark").text() + "</textarea></td></tr>";
        content += "</table>";

        $.dialog({
            title: "更新事件概率模板",
            content: content,
            button: [
                    {
                        name: "提交",
                        callback: function () {
                            EditPool();
                        }
                    },
                    {
                        name: "取消",
                        callback: function () {
                            this.close();
                        }
                    }
                    ],
            lock: true,
            drag: false
        });
    });

    function EditPool() {
        var id = $("#lblName").parent().parent().attr("id");
        var name = $("#txtName").val();
        var poolNum = $("#txtPoolNum").val();
        var editTime = $("#txtEditTime").val();
        var editNum = $("#txtEditNum").val();
        var poolBet = $("#txtPoolBet").val();
        var isOpen = $("input[name=radioIsOpen]:checked").val();
        var remark = $("#txtRemark").val();
        $.ajax({
            type: "post",
            data: { action: "Update", id: id, name: name, poolNum: poolNum, editTime: editTime, editNum: editNum, poolBet: poolBet, isOpen: isOpen, remark: remark },
            async: true,
            url: "../../Ajax/LotteryPoolAjax.ashx",
            beforeSend: function () {
            },
            success: function (data) {
                if (data) {
                    $("#lblName").text(name);
                    $("#lblPoolNum").text(poolNum);
                    $("#lblEditTime").text(editTime);
                    $("#lblEditNum").text(editNum);
                    $("#lblPoolBet").text(poolBet);
                    $.dialog.tips("更新成功！", 1);
                }
                else $.dialog.tips("更新失败！", 1);
            },
            complete: function () {
            },
            error: function () {
            }
        })
    }
})